package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import entity.Book;
import  dao.BookDAO;
import entity.Page;

/**
 * Servlet implementation class BookDelServlet
 */
@WebServlet("/deleteBook")
public class BookDelServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	BookDAO bookDao = new BookDAO();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BookDelServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String bookid = request.getParameter("id");
		String mes = "";
		if(bookid != null){
			int id = Integer.parseInt(bookid);
			
			if(bookDao.delete(id) > 0){
				mes = "删除成功！";
			} else {
				mes = "删除失败!";
			}
		} else {
			mes = "非法请求！";
		}
		request.setAttribute("MES", mes);
		request.getRequestDispatcher("BookShow").forward(request, response);
	}

}
